package seeders

import (
	"github.com/goravel/framework/facades"
	"math/rand"

	"goravel/app/models"
)

type UserSeeder struct {
}

// Signature The name and signature of the seeder.
func (s *UserSeeder) Signature() string {
	return "UserSeeder"
}

// Run executes the seeder logic.
func (s *UserSeeder) Run() error {
	password, _ := facades.Hash().Make("admin888")
	//随机8位
	randStr := func(seed int) string {
		str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
		bytes := []byte(str)
		result := []byte{}
		r := rand.New(rand.NewSource(100))
		for i := 0; i < seed; i++ {
			result = append(result, bytes[r.Intn(len(bytes))])
		}
		return string(result)
	}
	users := []models.User{
		{
			Name:     "admin",
			Email:    "admin@admin.com",
			Password: password,
			IDNumber: randStr(12),
			Mobile:   "18888888888",
			Gender:   1,
			State:    1,
		},
		{
			Name:     "user",
			Email:    "user@user.com",
			Password: password,
			IDNumber: randStr(8),
			Mobile:   "18888888889",
			Gender:   1,
		},
	}
	return facades.Orm().Query().Model(&models.User{}).Create(&users)
}
